package com.cuihanyu.newuniversityover.present;

import com.cuihanyu.newuniversityover.model.MVPModel;
import com.cuihanyu.newuniversityover.view.BaseMVPview;
import com.cuihanyu.newuniversityover.view.MVPView;
import com.zhy.http.okhttp.callback.StringCallback;

import okhttp3.Call;

/**
 * Created by cuihanyu on 2018/2/6.
 */

public class MVPPresent {
    private BaseMVPview mvpView;
    private MVPModel mvpModel;

    public MVPPresent() {
        mvpModel = new MVPModel();
    }

    /**
     * 绑定View
     *
     * @param mvpView
     */
    public void attachView(BaseMVPview mvpView) {
        this.mvpView = mvpView;
    }

    /**
     * 解绑View
     */
    public void detachView() {
        mvpView = null;
    }

    public void requestData(String url) {
        mvpModel.request(url, new StringCallback() {
            @Override
            public void onError(Call call, Exception e, int id) {
                mvpView.onError(call, e, id);
            }

            @Override
            public void onResponse(String response, int id) {
                mvpView.onResponse(response, id);
            }
        });
    }
}
